package com.group12.liuxinpeng.duty.controller;

import com.group12.liuxinpeng.common.control.BaseController;
import com.group12.liuxinpeng.duty.entity.SearchDutyEntity;
import com.group12.liuxinpeng.duty.service.DutyService;
import com.group12.liuxinpeng.mybatis.entity.PtDutyEntity;
import com.group12.liuxinpeng.mybatis.flexigrid.PadingRstType;
import com.group12.liuxinpeng.mybatis.flexigrid.PagingBean;
import com.group12.liuxinpeng.mybatis.ztree.ZtreeEntity;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/duty")
public class DutyController extends BaseController {
    private Logger logger = LogManager.getLogger(this.getClass());
    @Resource
    private DutyService dutyService;

    @RequestMapping("/dutyPage")
    public String dutyPage(){
        return "duty/dutyPage";
    }
    @RequestMapping("/queryDutyListPage")
    @ResponseBody
    public PadingRstType<PtDutyEntity> queryDutyListPage(SearchDutyEntity search, PagingBean paging){
        logger.info(search);
        logger.info(paging);
        PadingRstType<PtDutyEntity> ptDutyEntityPadingRstType = dutyService.queryDutyListPage(search,paging);
        return ptDutyEntityPadingRstType;
    }


    @RequestMapping("/getMenuTree")
    @ResponseBody
    public List<ZtreeEntity> getMenuTree(){
        return dutyService.getMenuTree();
    }

    @RequestMapping("/dutyAdd")
    @ResponseBody
    public String dutyAdd(PtDutyEntity ptDutyEntity){
        dutyService.dutyAdd(ptDutyEntity);
        return getSuccessMessage("role.add.success");
    }
    @RequestMapping("/dutyDelete")
    @ResponseBody
    public String roleDelete(String dutyId){
        System.out.println(dutyId);
        dutyService.dutyDelete(dutyId);
        return getSuccessMessage("role.delete.success");
    }
    @RequestMapping("/dutyUpdate")
    @ResponseBody
    public String roleUpdate(PtDutyEntity ptDutyEntity){
        dutyService.dutyUpdate(ptDutyEntity);
        return getSuccessMessage("role.update.success");
    }


}